package lian_xi;

import java.sql.SQLOutput;
import java.util.concurrent.atomic.AtomicStampedReference;

class Book{
    private String name;
    private double price;
    public Book(String name,double price){
        this.name = name;
        this.price = price;
    }
}
//通过AtomicStampedReference实现版本号的替换
public class YootkDemo4 {
    public static void main(String[] args) {
        Book book = new Book("java实战",23.2);
        AtomicStampedReference<Book> bookAtomicStampedReference = new AtomicStampedReference<>(book,1);
        bookAtomicStampedReference.compareAndSet(book,new Book("java实战",23.2),bookAtomicStampedReference.getStamp(),bookAtomicStampedReference.getStamp()+1);
        System.out.println(bookAtomicStampedReference.getReference());
        System.out.println("当前版本号： " + bookAtomicStampedReference.getStamp());
    }
}
